package com.mh.dao;

import com.mh.domain.Item;

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.skyway.spring.util.dao.AbstractJpaDao;

import org.springframework.dao.DataAccessException;

import org.springframework.stereotype.Repository;

import org.springframework.transaction.annotation.Transactional;

/**
 * DAO to manage Item entities.
 * 
 */
@Repository("ItemDAO")
@Transactional
public class ItemDAOImpl extends AbstractJpaDao<Item> implements ItemDAO {

	/**
	 * Set of entity classes managed by this DAO.  Typically a DAO manages a single entity.
	 *
	 * 
	 * @generated
	 */
	private final static Set<Class<?>> dataTypes = new HashSet<Class<?>>(Arrays.asList(new Class<?>[] { Item.class }));
	/**
	 * EntityManager injected by Spring for persistence unit mhtest
	 *
	 * 
	 * @generated
	 */
	@PersistenceContext(unitName = "mhtest")
	private EntityManager entityManager;

	/**
	 * Instantiates a new ItemDAOImpl
	 *
	 * 
	 * @generated
	 */
	public ItemDAOImpl() {
		super();
	}

	/**
	 * Get the entity manager that manages persistence unit 
	 *
	 * 
	 * @generated
	 */
	public EntityManager getEntityManager() {
		return entityManager;
	}

	/**
	 * Returns the set of entity classes managed by this DAO.
	 *
	 * 
	 * @generated
	 */
	public Set<Class<?>> getTypes() {
		return dataTypes;
	}

	/**
	 * JPQL Query - findItemByQuantity
	 *
	 */
	@Transactional
	public Set<Item> findItemByQuantity(Integer quantity1) throws DataAccessException {

		return findItemByQuantity(quantity1, -1, -1);
	}

	/**
	 * JPQL Query - findItemByQuantity
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Item> findItemByQuantity(Integer quantity1, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findItemByQuantity", startResult, maxRows, quantity1);
		return new LinkedHashSet<Item>(query.getResultList());
	}

	/**
	 * JPQL Query - findItemByCost
	 *
	 */
	@Transactional
	public Set<Item> findItemByCost(java.lang.Double cost1) throws DataAccessException {

		return findItemByCost(cost1, -1, -1);
	}

	/**
	 * JPQL Query - findItemByCost
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Item> findItemByCost(java.lang.Double cost1, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findItemByCost", startResult, maxRows, cost1);
		return new LinkedHashSet<Item>(query.getResultList());
	}

	/**
	 * JPQL Query - findItemByCreatedBy
	 *
	 */
	@Transactional
	public Set<Item> findItemByCreatedBy(String createdBy1) throws DataAccessException {

		return findItemByCreatedBy(createdBy1, -1, -1);
	}

	/**
	 * JPQL Query - findItemByCreatedBy
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Item> findItemByCreatedBy(String createdBy1, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findItemByCreatedBy", startResult, maxRows, createdBy1);
		return new LinkedHashSet<Item>(query.getResultList());
	}

	/**
	 * JPQL Query - findItemByCreatedOn
	 *
	 */
	@Transactional
	public Set<Item> findItemByCreatedOn(java.util.Date createdOn1) throws DataAccessException {

		return findItemByCreatedOn(createdOn1, -1, -1);
	}

	/**
	 * JPQL Query - findItemByCreatedOn
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Item> findItemByCreatedOn(java.util.Date createdOn1, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findItemByCreatedOn", startResult, maxRows, createdOn1);
		return new LinkedHashSet<Item>(query.getResultList());
	}

	/**
	 * JPQL Query - findItemByModifiedOn
	 *
	 */
	@Transactional
	public Set<Item> findItemByModifiedOn(java.util.Date modifiedOn1) throws DataAccessException {

		return findItemByModifiedOn(modifiedOn1, -1, -1);
	}

	/**
	 * JPQL Query - findItemByModifiedOn
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Item> findItemByModifiedOn(java.util.Date modifiedOn1, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findItemByModifiedOn", startResult, maxRows, modifiedOn1);
		return new LinkedHashSet<Item>(query.getResultList());
	}

	/**
	 * JPQL Query - findItemByModifiedByContaining
	 *
	 */
	@Transactional
	public Set<Item> findItemByModifiedByContaining(String modifiedBy1) throws DataAccessException {

		return findItemByModifiedByContaining(modifiedBy1, -1, -1);
	}

	/**
	 * JPQL Query - findItemByModifiedByContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Item> findItemByModifiedByContaining(String modifiedBy1, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findItemByModifiedByContaining", startResult, maxRows, modifiedBy1);
		return new LinkedHashSet<Item>(query.getResultList());
	}

	/**
	 * JPQL Query - findItemByModifiedBy
	 *
	 */
	@Transactional
	public Set<Item> findItemByModifiedBy(String modifiedBy1) throws DataAccessException {

		return findItemByModifiedBy(modifiedBy1, -1, -1);
	}

	/**
	 * JPQL Query - findItemByModifiedBy
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Item> findItemByModifiedBy(String modifiedBy1, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findItemByModifiedBy", startResult, maxRows, modifiedBy1);
		return new LinkedHashSet<Item>(query.getResultList());
	}

	/**
	 * JPQL Query - findAllItems
	 *
	 */
	@Transactional
	public Set<Item> findAllItems() throws DataAccessException {

		return findAllItems(-1, -1);
	}

	/**
	 * JPQL Query - findAllItems
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Item> findAllItems(int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAllItems", startResult, maxRows);
		return new LinkedHashSet<Item>(query.getResultList());
	}

	/**
	 * JPQL Query - findItemById
	 *
	 */
	@Transactional
	public Item findItemById(Integer id1) throws DataAccessException {

		return findItemById(id1, -1, -1);
	}

	/**
	 * JPQL Query - findItemById
	 *
	 */

	@Transactional
	public Item findItemById(Integer id1, int startResult, int maxRows) throws DataAccessException {
		try {
			Query query = createNamedQuery("findItemById", startResult, maxRows, id1);
			return (com.mh.domain.Item) query.getSingleResult();
		} catch (NoResultException nre) {
			return null;
		}
	}

	/**
	 * JPQL Query - findItemByPrimaryKey
	 *
	 */
	@Transactional
	public Item findItemByPrimaryKey(Integer id) throws DataAccessException {

		return findItemByPrimaryKey(id, -1, -1);
	}

	/**
	 * JPQL Query - findItemByPrimaryKey
	 *
	 */

	@Transactional
	public Item findItemByPrimaryKey(Integer id, int startResult, int maxRows) throws DataAccessException {
		try {
			Query query = createNamedQuery("findItemByPrimaryKey", startResult, maxRows, id);
			return (com.mh.domain.Item) query.getSingleResult();
		} catch (NoResultException nre) {
			return null;
		}
	}

	/**
	 * JPQL Query - findItemByCreatedByContaining
	 *
	 */
	@Transactional
	public Set<Item> findItemByCreatedByContaining(String createdBy1) throws DataAccessException {

		return findItemByCreatedByContaining(createdBy1, -1, -1);
	}

	/**
	 * JPQL Query - findItemByCreatedByContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Item> findItemByCreatedByContaining(String createdBy1, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findItemByCreatedByContaining", startResult, maxRows, createdBy1);
		return new LinkedHashSet<Item>(query.getResultList());
	}

	/**
	 * Used to determine whether or not to merge the entity or persist the entity when calling Store
	 * @see store
	 * 
	 *
	 */
	public boolean canBeMerged(Item entity) {
		return true;
	}
}
